<template>
	<nt-container :key="detailKey">
		<nt-grid :data="entryList" @click="toPage"></nt-grid>
		<view class="detail" v-if="!pageLoading">
			<view class="nt-submit-item">
				<nt-order-detail :orderInfo="orderInfo" :key="detailKey"></nt-order-detail>
			</view>
			<div class="card-showlog">
				<div class="btn" @tap="showLog = !showLog">{{ !showLog ? '显示事件' : '隐藏事件' }}</div>
			</div>
			<nt-card label="订单事件日志" v-if="showLog && orderInfo.eventlog.length > 0">
				<view class="card">
					<view class="card-item card-eventlog" v-for="(it, index) in orderInfo.eventlog" :key="it.id">
						<view class="card-item__label">{{ it.create_time }}</view>
						<view class="card-item__right space">{{ it.remarks }}</view>
					</view>
				</view>
			</nt-card>
			<view v-if="orderInfo.typetable_list && orderInfo.typetable_list.length > 0">
				<view v-for="(it, index) in orderInfo.typetable_list" :key="it.id">
					<nt-card :label="it.header.title">
						<template #button>
							<view @tap="showTypeTableList(it.header.showBodyStatus, index)" :class="{
								'typetable-icon': it.header.showBodyStatus === 1
							}">
								<text class="iconfont icon">&#xe622;</text>
							</view>
						</template>
						<view v-if='it.header.showBodyStatus === 1'>
							<view class="card" v-for="(c, idx) in it.body" :key="idx">
								<view class="card-item card-eventlog">
									<view class="card-item__label" style="width: 140rpx;flex-shrink: 0;text-align-last: auto">{{ c.text }}</view>
									<view class="card-item__right end">{{ c.value }}</view>
								</view>
							</view>
							<view class="card typetable-footer " v-if="it.footer && it.footer.length > 0">
								<view class="card-item card-eventlog" style="padding-right:4rpx;" v-for="(f, idx) in it.footer" :key="idx">
									<view class="card-item__label" style="width:auto;max-width: 100rpx;flex-shrink: 0;text-align-last: auto;margin-right: 10rpx;">{{ f.text }}</view>
									<view class="card-item__right end" style="color:red">{{ f.value }}</view>
								</view>
							</view>
						</view>
					</nt-card>
				</view>
			</view>
			<nt-card label="下单/返利信息"
				v-if="orderInfo.orderbefore || orderInfo.rebate_type>0 || orderInfo.rebate_type2>0">
				<view class="h_cardBox" v-if="orderInfo.orderbefore">
					<view class="h_box">
						<view class="h_t1">下单ID：</view>
						<view class="h_t2">{{orderInfo.orderbefore.id}}</view>
					</view>
					<view class="h_box">
						<view class="h_t1">下单时间：</view>
						<view class="h_t2">{{orderInfo.orderbefore.create_date.slice(0,11)}}</view>
					</view>
					<view class="h_box">
						<view class="h_t1">下单用户：</view>
						<view class="h_t2">{{orderInfo.orderbefore.username}}</view>
					</view>
					<view class="h_box">
						<view class="h_t1">微信名称：</view>
						<view class="h_t2">{{orderInfo.orderbefore.useropenname}}</view>
					</view>
					<view class="h_box">
						<view class="h_t1">微信绑定师傅：</view>
						<view class="h_t2">{{orderInfo.orderbefore.bind_wrokername}}</view>
					</view>
					<view class="h_box">
						<view class="h_t1">绑定时间：</view>
						<view class="h_t2">{{orderInfo.orderbefore.bind_time}}</view>
					</view>
				</view>
				<view class="h_cardBox" v-if="orderInfo.rebate_type>0">
					<view class="h_box">
						<view class="h_t1">返利类型：</view>
						<view class="h_t2">{{orderInfo.rebate_type1_text}}</view>
					</view>
					<view class="h_box">
						<view class="h_t1">返利状态：</view>
						<view class="h_t2">{{orderInfo.rebate_status1_text}}</view>
					</view>
					<view class="h_box">
						<view class="h_t1">返利用户：</view>
						<view class="h_t2">{{orderInfo.rebate_username1}}</view>
					</view>
					<view class="h_box">
						<view class="h_t1">返利金额：</view>
						<view class="h_t2">{{orderInfo.rebate_price1_text}}</view>
					</view>
				</view>
				<view class="h_cardBox" v-if="orderInfo.rebate_type2>0">
					<view class="h_box">
						<view class="h_t1">返利类型：</view>
						<view class="h_t2">{{orderInfo.rebate_type2_text}}</view>
					</view>
					<view class="h_box">
						<view class="h_t1">返利状态：</view>
						<view class="h_t2">{{orderInfo.rebate_status2_text}}</view>
					</view>
					<view class="h_box">
						<view class="h_t1">返利用户：</view>
						<view class="h_t2">{{orderInfo.rebate_username2}}</view>
					</view>
					<view class="h_box">
						<view class="h_t1">返利金额：</view>
						<view class="h_t2">{{orderInfo.rebate_price2_text}}</view>
					</view>
				</view>
			</nt-card>
			<template v-for="(arItem,arIndex) in orderInfo.applyreturn">
				<nt-card :label="`申请${arItem.is_type}记录`" v-if="arItem.status===0" :key="arItem.id">
					<template #button>
						<div class="copy" @tap="updateOrderApplyLog(arItem.id, arItem.is_type)">修改</div>
					</template>
					<view class="h_cardBox2" :key="arIndex" v-if="arItem.status == 0">
						<view class="h_box">
							<view class="h_t1">申请类型</view>
							<view class="h_t2" v-if="arItem.is_type">{{arItem.is_type}}</view>
						</view>
						<view class="h_box" v-if="arItem.status_text">
							<view class="h_t1">申请状态</view>
							<view class="h_t3">{{arItem.status_text}}</view>
						</view>
						<view class="h_box" v-if="arItem.create_time">
							<view class="h_t1">申请时间</view>
							<view class="h_t2">{{arItem.create_time}}</view>
						</view>
						<view class="h_box h_box2" v-if="arItem.images_list.length>0">
							<view class="h_t1">申请图片</view>
							<view class="h_imgList">
								<!-- <view class="h_imgbox" v-for="(imgItem,imgIndex) in arItem.images_list" :key="imgIndex"> -->
								<nt-upload :images="arItem.images_list" mode="preview" v-if="!hidden"></nt-upload>
								<!-- </view> -->
							</view>
						</view>
						<view class="h_box" v-if="arItem.content">
							<view class="h_t1">师傅备注</view>
							<view class="h_t2">{{arItem.content}}</view>
						</view>
						<view class="h_box" v-if="arItem.picked">
							<view class="h_t1">自提点</view>
							<view class="h_t2">{{arItem.picked}}</view>
						</view>
						<view class="h_box" v-if="arItem.picked_price > 0">
							<view class="h_t1">自提点金额</view>
							<view class="h_t3">{{arItem.picked_price}}元</view>
						</view>
						<view class="h_box" v-if="arItem.picked_remarks">
							<view class="h_t1">自提点备注</view>
							<view class="h_t2">{{arItem.picked_remarks}}</view>
						</view>
					</view>

				</nt-card>
			</template>

			<nt-card label="录入信息" v-if="quote.length > 0">
				<template #button>
					<div class="copy" @tap="copyOrderInfo">复制</div>
				</template>
				<view class="card">

					<view class="card-item">
						<view class="card-item__label">{{orderInfo.is_type}}内容</view>
						<view class="card-item__right">{{orderInfo.problem}}</view>
					</view>
					<view class="card-item" v-for="(it, index) in quote" :key="it.id">
						<view class="card-item__label">报价内容</view>
						<view class="card-item__right space">
							<view class="card-item__remarks">{{ it.content }}</view>
							<view class="card-item__price">{{ it.price }}元</view>
						</view>
					</view>
					<view class="card-item">
						<view class="card-item__label">总报价</view>
						<view class="card-item__right space amount">{{ orderInfo.order_price }}元</view>
					</view>
				</view>
			</nt-card>

			<nt-card label="本人带回" v-if="orderInfo.selftakeback_images_list.length>0">
				<view class="card">
					<view class="card-item">
						<view class="card-item__label">带回图片</view>
						<view class="card-item__right"> <nt-upload :images="orderInfo.selftakeback_images_list"
								mode="preview"></nt-upload></view>
					</view>
					<view class="card-item">
						<view class="card-item__label">备注</view>
						<view class="card-item__right">{{orderInfo.selftakeback_remarks}}</view>
					</view>
				</view>
			</nt-card>
			<nt-card label="返修信息" v-if="orderInfo.is_type === '返修'">
				<view class="card">
					<view class="card-item">
						<view class="card-item__label">返修类型</view>
						<view class="card-item__right">{{orderInfo.problem_type}}</view>
					</view>
					<view class="card-item">
						<view class="card-item__label">返修内容</view>
						<view class="card-item__right">{{orderInfo.problem}}</view>
					</view>
				</view>
			</nt-card>
			<nt-card label="服务内容" v-if="orderInfo.repair_status">
				<view class="card">
					<view class="card-item">
						<view class="card-item__label">服务内容</view>
						<view class="card-item__right">{{formConfig.repairstatusList[orderInfo.repair_status]}}</view>
					</view>
				</view>
			</nt-card>
			<nt-card label="总成本" :sub="`${tatalCost}元`">
				<view class="card">
					<view class="card-item">
						<view class="card-item__label">单费</view>
						<view class="card-item__right space">
							<view class="card-item__remarks"></view>
							<view class="card-item__price">{{ orderInfo.cost || 0 }}元</view>
						</view>
					</view>
					<view class="card-item">
						<view class="card-item__label">带会成本</view>
						<view class="card-item__right space">
							<view class="card-item__remarks"></view>
							<view class="card-item__price">{{ orderInfo.cost_back_parts_price }}元</view>
						</view>
					</view>
					<view class="card-item" v-if="invoice">
						<view class="card-item__label">税与邮费</view>
						<view class="card-item__right space">
							<view class="card-item__remarks"></view>
							<view class="card-item__price">{{ invoice.postage }}元</view>
						</view>
					</view>
					<template v-if="companyPartsList.length">
						<view class="card-item__label subtitle">公司配件</view>
						<view class="card-item">
							<view class="card-item__cell">名称</view>
							<view class="card-item__cell">数量</view>
							<view class="card-item__cell">价格</view>
						</view>
						<view class="card-item" v-for="(it, index) in companyPartsList" :key="it.id">
							<view class="card-item__cell">{{ it.content }}</view>
							<view class="card-item__cell">{{ it.number }}</view>
							<view class="card-item__cell">{{ it.price }}</view>
						</view>
					</template>
					<template v-if="personPartsList.length">
						<view class="card-item__label subtitle">个人配件</view>
						<view class="card-item">
							<view class="card-item__cell">名称</view>
							<view class="card-item__cell">数量</view>
							<view class="card-item__cell">价格</view>
						</view>
						<view class="card-item" v-for="(it, index) in personPartsList" :key="it.id">
							<view class="card-item__cell">{{ it.content }}</view>
							<view class="card-item__cell">{{ it.number }}</view>
							<view class="card-item__cell">{{ it.price }}</view>
						</view>
					</template>

					<template v-if="procurePartsList.length">
						<view class="card-item__label subtitle">申购配件</view>
						<view class="card-item">
							<view class="card-item__cell">名称</view>
							<view class="card-item__cell">数量</view>
							<view class="card-item__cell">价格</view>
						</view>
						<view class="card-item" v-for="(it, index) in procurePartsList" :key="it.id">
							<view class="card-item__cell">{{ it.content }}</view>
							<view class="card-item__cell">{{ it.number }}</view>
							<view class="card-item__cell">{{ it.price }}</view>
						</view>
					</template>
					<view class="card-item a-start">
						<view class="card-item__label">报销图</view>
						<view class="card-item__right start">
							<nt-upload :images="orderInfo.purchase_images" mode="preview"></nt-upload>
						</view>
					</view>
					<template v-if="takebackList.length">
						<view class="card-item__label subtitle">带回配件</view>
						<view class="card-item">
							<view class="card-item__cell">名称</view>
							<view class="card-item__cell">内容</view>
							<view class="card-item__cell">数量</view>
							<view class="card-item__cell">价格</view>
						</view>
						<view class="card-item" v-for="(it, index) in takebackList" :key="it.id">
							<view class="card-item__cell">{{ it.takeback_parts_name }}</view>
							<view class="card-item__cell">{{ it.content || "--" }}</view>
							<view class="card-item__cell">{{ it.number }}</view>
							<view class="card-item__cell">{{ it.takeback_parts_price }}</view>
						</view>
					</template>
					<template v-if="takeback_images.length>0">
						<view class="card-item__label subtitle">带回配件图片</view>
						<nt-upload mode="preview" :images="takeback_images"></nt-upload>
					</template>
				</view>
			</nt-card>

			<nt-card label="支付信息" v-if="payment.length > 0">
				<view class="card">
					<template v-for="(it, index) in payment">
						<view class="card-item" :key="it.index">
							<view class="card-item__label">支付方式</view>
							<view class="card-item__right space">
								<view class="card-item__remarks">{{ it.paytype }}</view>
								<view class="card-item__price">
									<span class="copy" style="margin-right: 10rpx;"
										v-if="orderInfo.nav_status_text === 7 && it.paytype === '签单'"
										@tap="nav(`/subpackage/order/pages/payment/signing?id=${orderInfo.id}`)">修改</span>
									{{ it.payprice }}元
								</view>
							</view>
						</view>
						<view class="card-item" :key="it.id" v-if="it.paytype === '美团/大众'">
							<view class="card-item__right space">
								<view style="padding-right: 20rpx;">
									<text style="font-weight: bold;color:#f00">店名：</text>
									<text
										v-if="it.receiptcode&&it.receiptcode.openshop">【{{ it.receiptcode.openshop.branchname}}】{{ it.receiptcode.shopname }}</text>
								</view>
								<view class="">
									<text style="font-weight: bold;color:#f00">券码：</text>
									{{ it.receipt_code }}
								</view>
							</view>
						</view>
					</template>
					<view class="card-item a-start">
						<view class="card-item__label">支付截图</view>
						<view class="card-item__right start">
							<!-- payimages -->
							<nt-upload :images="orderInfo.payimages" mode="preview"></nt-upload>
						</view>
					</view>
				</view>
			</nt-card>

			<nt-card label="发票" v-if="invoice">
				<view class="card">
					<view class="card-item">
						<view class="card-item__label">发票</view>
						<view class="card-item__right block">
							<view style="line-height: 2">状态：
								<text>{{ invoice.status === 0 ? '未开票' : '已开票' }}</text>
							</view>
							<view style="line-height: 2" v-if="invoice.invoice_create_time">开票时间：
								{{ invoice.invoice_create_time }}
							</view>
							<view style="line-height: 2">开票备注： {{ invoice.invoice_content }}</view>
							<view style="line-height: 2" v-if="invoice.pdffile_list.length">开票备注：
								<text v-for="(it,index) in invoice.pdffile_list" :key="index" @tap="downloadInvoice(it)"
									style="margin-left:10rpx">查看附件{{index+1}}</text>
							</view>
						</view>
					</view>
				</view>
			</nt-card>

			<nt-card label="好评" v-if="orderInfo.is_praise > 0">
				<view class="card" v-for="(item,index) in orderInfo.praise_list" :key="item.create_time">
					<view class="card-item a-start">
						<view class="card-item__label">好评截图</view>
						<view class="card-item__right start">
							<nt-upload :images="item.images_list ? item.images_list: []" mode="preview"></nt-upload>
						</view>
					</view>
					<view class="card-item">
						<view class="card-item__label">好评类型</view>
						<view class="card-item__right">{{ item.praise_type_text }}</view>
					</view>
					<view class="card-item" style="border-bottom:1px solid #dee1e6">
						<view class="card-item__label">好评状态</view>
						<view class="card-item__right">{{ item.review_status_text }}</view>
					</view>
				</view>
			</nt-card>
			<nt-card label="广告图" v-if="orderInfo.gg_img || (orderInfo.orderattr && orderInfo.orderattr.gg_remarks)">
				<view class="card">
					<view class="card-item a-start" v-if="orderInfo.gg_img">
						<view class="card-item__label">广告图片</view>
						<view class="card-item__right start">
							<nt-upload :images="orderInfo.gg_img ? [orderInfo.gg_img] : []" mode="preview"></nt-upload>
						</view>
					</view>
					<view class="card-item a-start" v-if="orderInfo.orderattr.gg_remarks">
						<view class="card-item__label">广告图备注</view>
						<view class="card-item__right start">{{orderInfo.orderattr.gg_remarks}}</view>
					</view>
				</view>
			</nt-card>

			<nt-card label="其他">
				<view class="card">
					<view class="card-item" v-if="orderInfo.warranty_date">
						<view class="card-item__label">保修期</view>
						<view class="card-item__right">{{ orderInfo.warranty_date }}</view>
					</view>
					<view class="card-item">
						<view class="card-item__label">师傅</view>
						<view class="card-item__right">{{ orderInfo.worker_name }}</view>
					</view>
					<view class="card-item">
						<view class="card-item__label">利润</view>
						<view class="card-item__right amount">{{ orderInfo.profit }}元</view>
					</view>
				</view>
			</nt-card>

			<template v-if="orderInfo.orderbranch && orderInfo.orderbranch.length">
				<nt-card :label="`${it.is_type}信息`" v-for="(it, index) in orderInfo.orderbranch" :key="index">
					<template #button>
						<div class="copy" v-if="isCanUpdateSendInfo(it)" @tap="updateSendInfo(it)">修改</div>
					</template>
					<view class="card">
						<view class="card-item a-start">
							<view class="card-item__label end">师傅备注</view>
							<view class="card-item__right end">{{ it.return_worker_remarks }}</view>
						</view>
						<view class="card-item a-start" v-if="it.return_worker_images.length">
							<view class="card-item__label">师傅图片</view>
							<view class="card-item__right start">
								<nt-upload :images="it.return_worker_images" mode="preview" v-if="!hidden"></nt-upload>
							</view>
						</view>
						<view class="card-item">
							<view class="card-item__label">状态</view>
							<view class="card-item__right end">{{ it.status_text }}</view>
						</view>
						<view class="card-item" v-if="it.worker_id">
							<view class="card-item__label">送机学徒</view>
							<view class="card-item__right end">{{ it.worker_name }}</view>
						</view>
						<template v-if="it.is_praise != 0">
							<template v-for="item in it.praise_list">
								<view class="card-item" :key="item.create_time">
									<view class="card-item__label">好评类型</view>
									<view class="card-item__right end">{{ item.praise_type_text }}</view>
								</view>
								<view class="card-item">
									<view class="card-item__label">好评审核状态</view>
									<view class="card-item__right end">{{ item.review_status_text }}</view>
								</view>
								<view class="card-item a-start" style="border-bottom:1px solid #dee1e6"
									v-if="item.images_list.length">
									<view class="card-item__label">好评图片</view>
									<view class="card-item__right start">
										<nt-upload :images="item.images_list" mode="preview" v-if="!hidden"></nt-upload>
									</view>
								</view>
							</template>
						</template>


						<view class="card-item">
							<view class="card-item__label">佣金</view>
							<view class="card-item__right end">{{ setCommission(it) }}</view>
						</view>
						<template v-if="it.fixcashreward">
							<view class="card-item">
								<view class="card-item__label">{{orderInfo.worker_name}}打赏</view>
								<view class="card-item__right end">{{ it.fixcashreward.money }}</view>
							</view>
						</template>

						<view class="card-item" v-if="it.picked">
							<view class="card-item__label">自提点</view>
							<view class="card-item__right end">{{ it.picked }}</view>
						</view>
						<view class="card-item" v-if="it.picked_price">
							<view class="card-item__label">自提金额</view>
							<view class="card-item__right end">{{ it.picked_price }}</view>
						</view>
						<view class="card-item" v-if="it.picked_remarks">
							<view class="card-item__label">自提备注</view>
							<view class="card-item__right end">{{ it.picked_remarks }}</view>
						</view>


						<view class="card-item" v-if="it.delivery_time">
							<view class="card-item__label">送机完成时间</view>
							<view class="card-item__right end">{{ it.delivery_time }}</view>
						</view>
						<view class="card-item">
							<view class="card-item__label">更新时间</view>
							<view class="card-item__right end">{{ it.update_time }}</view>
						</view>
					</view>
				</nt-card>
			</template>

			<nt-card label="申请加班奖励" v-if="orderInfo.overtime">
				<view class="card">
					<view class="card-item">
						<view class="card-item__label">状态</view>
						<view class="card-item__right">{{ orderInfo.overtime.status_text }}</view>
					</view>
					<view class="card-item">
						<view class="card-item__label">用户名</view>
						<view class="card-item__right">{{ orderInfo.overtime.user_name }}</view>
					</view>
					<view class="card-item a-start">
						<view class="card-item__label">图片</view>
						<view class="card-item__right start">
							<nt-upload :images="orderInfo.overtime.images_list" mode="preview"></nt-upload>
						</view>
					</view>
					<view class="card-item">
						<view class="card-item__label">备注</view>
						<view class="card-item__right">{{ orderInfo.overtime.remarks }}</view>
					</view>
					<view class="card-item">
						<view class="card-item__label">申请时间</view>
						<view class="card-item__right">{{ orderInfo.overtime.create_date }}</view>
					</view>
					<view class="card-item" v-if="orderInfo.overtime.is_review === 1">
						<view class="card-item__label">审核时间</view>
						<view class="card-item__right">{{ orderInfo.overtime.review_date }}</view>
					</view>
				</view>
			</nt-card>

			<nt-card label="退款信息" v-if="orderInfo.orderrefund && orderInfo.orderrefund.length > 0">
				<view class="card" v-for="(it,index) in orderInfo.orderrefund" :key="index">
					<view class="card-item">
						<view class="card-item__label">申请退款金额</view>
						<view class="card-item__right amount">{{ it.money }}元</view>
					</view>
					<view class="card-item" v-if="it.images.length">
						<view class="card-item__label">退款图片</view>
						<view class="card-item__right start">
							<nt-upload :images="it.images" mode="preview"></nt-upload>
						</view>
					</view>
					<view class="card-item">
						<view class="card-item__label">申请退款状态</view>
						<view class="card-item__right red">{{ it.status_text }}</view>
					</view>
					<view class="card-item">
						<view class="card-item__label">申请退款备注</view>
						<view class="card-item__right red">{{ it.remark }}</view>
					</view>
				</view>
			</nt-card>
			<view class="detail-footer">
				<template v-if="orderInfo.powerStatus">
					<view class="detail-footer__btn"
						@tap="nav(`/subpackage/order/pages/submit/form?id=${orderInfo.id}&mode=invoice`)"
						v-if="orderInfo.powerStatus.postInvoiceEdit === 1">发票信息</view>
					<view class="detail-footer__btn"
						@tap="nav(`/subpackage/order/pages/submit/form?id=${orderInfo.id}&mode=refund`)"
						v-if="orderInfo.powerStatus.postApplyRefund === 1">申请退款</view>
					<view class="detail-footer__btn"
						@tap="nav(`/subpackage/order/pages/submit/form?id=${orderInfo.id}&mode=update`)"
						v-if="orderInfo.powerStatus.postApplyUpdate === 1">申请修改</view>
				</template>
			</view>

			<nt-order-more :show="showMore" @close="showMore = $event" :auth="orderInfo.powerStatus" :id="orderInfo.id"
				:is_type="orderInfo.is_type" :is_submit="orderInfo.is_submit" @refresh="getDetail"></nt-order-more>
		</view>
		<view class="progress-container" v-if="isShowProgress">
			<view class="progress-box">
				<view class="text">文件下载中，请稍后......</view>
				<progress :percent="progress" show-info stroke-width="3" />
			</view>
		</view>
	</nt-container>
</template>

<script>
	import {
		getOrderDetail,
		getCommonFormConfig
	} from "@/api"
	import {
		appConfig
	} from "@/config"
	import {
		authMap
	} from "@/utils"
	import {
		downloadFile
	} from '@/utils/request'
	export default {
		data() {
			return {
				pageLoading: true,
				orderId: "",
				orderInfo: {},
				// 报价内容
				quote: [],
				// 公司配件
				companyPartsList: [],
				// 个人配件
				personPartsList: [],
				// 申购配件
				procurePartsList: [],
				// 支付信息
				payment: [],
				// 带回配件
				takebackList: [],
				takeback_images: [],
				// 发票信息
				invoice: null,
				entryList: [],
				showMore: false,
				showLog: false,
				arShow: false,
				formConfig: {},
				hidden: true,
				isShowProgress: false,
				detailKey: Math.random()
			}
		},
		computed: {
			// 总报价
			totalQuotation() {
				return this.quote.reduce((acc, item) => acc += Number(item.price), 0)
			},
			// 带回成本
			bringBackCosts() {
				return this.takebackList.reduce((acc, item) => acc += Number(item.takeback_parts_price) * item.number, 0)
			},
			// 总成本
			tatalCost() {
				const {
					cost,
					tax_postage_price,
					cost_back_parts_price,
					order_parts_price
				} = this.orderInfo;
				if (typeof Number(cost) === "number" && typeof Number(tax_postage_price) === "number" && typeof Number(
						cost_back_parts_price) === "number" && typeof Number(order_parts_price) === "number") {
					return Number(cost) + Number(tax_postage_price) + Number(cost_back_parts_price) + Number(
						order_parts_price)
				}
				return 0
			},
		},
		onShow() {
			this.init()
		},
		onHide() {
			console.log("onHiden")
			this.hidden = true
		},
		onLoad(options) {
			this.orderId = options.id
		},
		methods: {
			downloadInvoice(url) {
				const downloadTask = uni.downloadFile({
					url: appConfig.imgCDN + url,
					success: res => {
						if (res.statusCode === 200) {
							this.isShowProgress = false;
							console.log('下载成功');
						}
						let that = this;
						uni.saveFile({
							tempFilePath: res.tempFilePath,
							success: function(red) {
								that.isShowProgress = false;
								uni.showModal({
									title: '提示',
									content: '文件已保存：' + red.savedFilePath,
									cancelText: '我知道了',
									confirmText: '打开文件',
									success: function(res) {
										if (res.confirm) {
											uni.openDocument({
												filePath: red.savedFilePath,
												success: (sus) => {
													console.log('成功打开');
												}
											})
										}
									}
								});
							}
						});
					}
				})

				downloadTask.onProgressUpdate((res) => {
					if (res.progress > 0) {
						this.isShowProgress = true;
					}
					this.progress = res.progress;
					console.log('下载进度：' + res.progress);
					console.log('已下载长度：' + res.totalBytesWritten);
					console.log('文件总长度：' + res.totalBytesExpectedToWrite);
				})
				// downloadFile(url)
				/* var dtask = plus.downloader.createDownload(appConfig.imgCDN+url, {}, function(d, status){
					// 下载完成
					if(status == 200){ 
						console.log("Download success: " + d.filename);
					} else {
						 console.log("Download failed: " + status); 
					}  
				});
				console.log(dtask, 'dtask')
				//dtask.addEventListener("statechanged", onStateChanged, false);
				dtask.start(); */
			},
			// 是否可以修改送机信息
			isCanUpdateSendInfo(it) {
				return it?.recordapplyreturn.powerStatus.editApplyReturn === 1
			},
			// 修改送返信息
			updateSendInfo(it) {
				const key = authMap.get(it.recordapplyreturn.is_type).key
				if (!key) return toast('权限错误')
				this.nav(
					`/subpackage/order/pages/submit/form?key=${key}&id=${this.orderInfo.id}&mode=order&return_id=${it.recordapplyreturn.id}`
				)
			},
			toPage(index) {
				const data = this.entryList[index]
				if (!data.url && data.type === 'more') {
					this.showMore = true
					return;
				}
				this.nav(`${data.url}?id=${this.orderId}`)
			},
			// 佣金
			setCommission(data) {
				const {
					is_city_profit,
					city_profit,
					is_worker_profit,
					worker_profit
				} = data;
				const total = (is_city_profit == 0 ? 0 : Number(city_profit)) + (is_worker_profit == 0 ? 0 : Number(
					worker_profit))
				return `${is_worker_profit ==0 ? '未设置' : worker_profit}(师傅) + ${is_city_profit ==0 ? '未设置' : city_profit}(公司) = ${total}元`
			},

			// 获取配件
			getFormConfig(type) {
				return getCommonFormConfig(this.orderId).then(res => {
					console.log(res, '获取配件')
					const {
						code,
						data
					} = res;
					if (code !== 1) return;
					this.formConfig = data
				})
			},
			// 订单详情
			getDetail() {
				getOrderDetail(this.orderId).then(res => {
					this.hidden = false
					const {
						code,
						data,
						msg
					} = res;
					let that = this;
					if (code !== 1) return this.toast(msg)
					this.orderInfo = data;
					for (const key in data) {
						this.orderInfo[key] = data[key]
					}
					this.detailKey = Math.random()
					this.pageLoading = false
					// 报价内容
					this.quote = data.quote || []
					// 公司配件
					this.companyPartsList = (data.partscompany || []).filter(item => item.is_new === 0)
					// 个人配件
					// this.personPartsList = data.partsperson || []
					this.personPartsList = this.personPartsEcho(data.partsperson || [])
					// 申购配件
					this.procurePartsList = (data.partscompany || []).filter(item => item.is_new === 1)
					this.payment = data.payment || []
					this.takebackList = data.takeback || []
					this.takeback_images = data.takeback_images || []
					this.invoice = data.invoice || null
					this.entryList = [{
							label: "验券",
							icon: "/static/image/yanquan.png",
							url: '/subpackage/order/pages/check-ticket/index',
							visiable: data.powerStatus.postPayment === 1
						},
						{
							label: "支付提交",
							icon: "/static/image/yanquan.png",
							url: '/subpackage/order/pages/payment/index',
							visiable: data.powerStatus.postPayment === 1
						},
						{
							label: "历史记录",
							icon: "/static/image/history.png",
							url: '/subpackage/order/pages/history/index',
							visiable: true
						},
						{
							label: "更多功能",
							icon: "/static/image/more.png",
							url: "",
							type: "more",
							visiable: true
						}
					]
				})
			},
			// 处理公司配件和申购配件回显
			personPartsEcho(data) {
				const p = []
				data.map(item => {
					let list = this.formConfig.partsPersonList
					for (let i = 0; i < list.length; i++) {
						if (item.parts_person_id === list[i].value) {
							p.push({
								id: item.id,
								content: list[i].name,
								price: list[i].price,
								number: item.number
							})
						}
					}
				})
				return p
			},
			// 修改送返等记录
			updateOrderApplyLog(return_id, is_type) {
				console.log()
				let key = authMap.get(is_type).key
				if (key) {
					this.nav(
						`/subpackage/order/pages/submit/form?key=${key}&id=${this.orderInfo.id}&mode=order&return_id=${return_id}`
					)
				}
			},
			async init() {
				await this.getFormConfig()
				this.getDetail()
			},
			showTypeTableList(showBodyStatus, index){
				this.orderInfo.typetable_list[index].header.showBodyStatus = showBodyStatus === 1 ? 0 : 1
			},
			// 复制
			copyOrderInfo() {
				// 订单号：2023070618103451370
				// --------报价内容--------
				// 光路凹凸镜=>300.00元
				// 主机维修=>150.00元
				// 偏光镜=>450.00元
				// 总报价:900 元
				// --------成本内容--------
				// 单费=>0元
				// 申购配件=>维修费用=>1X400元
				// 总成本:400 元
				// --------支付方式--------
				// 【黄帅提交】收款二维码=>已对账
				// =>150.00元
				// 美团/大众=>已对账
				// =>50.00元
				// 现金=>未对账
				// =>确认对账
				// =>700.00元
				// 支付截图:有
				// 好评状态:有
				// 维修师傅:黄帅  利润:500 元
				const {
					ordernumber,
					quote,
					payment,
					order_price,
					cost,
					partscompany,
					payimages,
					hp_img,
					worker_name,
					profit,
					takeback,
					partsperson
				} = this.orderInfo
				let number = `订单号：${ordernumber}`
				let baoja = quote.reduce((str, item) => {
					return str += `${item.content}=>${item.price || 0}元`
				}, '')
				let paymentStr = payment.reduce((str, item) => {
					return str +=
						`【${item.worker_name}提交】=>${item.paytype}=>${item.is_submit === 1 ? '已对账' : '未对账'}=>${item.payprice}元`
				}, '')
				let parts1 = partscompany.reduce((str, item) => {
					return str +=
						`${item.is_new == 0 ? '公司配件' : '申购配件'}=>${item.parts_name}=>${item.number || 1}X${item.price}元\r`
				}, '')
				let partspersonStr = partsperson.reduce((str, item) => {
					return str += `个人配件=>${item.content || ''}=>${item.number || 1}X${item.price || ''}元\r`
				}, '')
				let takebackStr = takeback.reduce((str, item) => {
					return str +=
						`${item.takeback_parts_type}=>${item.takeback_parts_name}=>${item.takeback_number || 1}X${item.takeback_parts_price}元\r`
				}, "")
				let result = `
${number}
--------报价内容--------
${baoja}
总报价:${order_price}元
--------成本内容--------
单费=>${cost || 0}元
${parts1}
${partspersonStr}
${takebackStr}
总成本：${this.tatalCost || 0}元
--------支付方式--------
${paymentStr}
支付截图:${payimages.length > 0 ? '有':'无'}
好评状态：${hp_img ? '有' : '无'}
维修师傅：${worker_name}  利润：${profit}元
			`
				this.copyText(result)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.h_cardBox {
		display: flex;
		flex-wrap: wrap;
		padding-top: 20rpx;
		margin-bottom: 17rpx;
		border-top: 1px solid #DDDDDD;

		&:first-child {
			border: none;
		}

		&:last-child {
			margin-bottom: 0;
		}

		.h_box {
			width: 50%;
			display: flex;
			font-size: 26rpx;
			line-height: 46rpx;
			color: #666;

			.h_t2 {
				color: #f00;
			}
		}
	}

	.h_cardBox2 {
		border-top: 1px solid #DDDDDD;

		&:first-child {
			border: none;
		}

		.h_box {
			display: flex;
			justify-content: space-between;
			padding: 20rpx 0;
			font-size: 26rpx;

			.h_t1 {
				color: #333;
				white-space: nowrap;
				margin-right: 26rpx;
			}

			.h_t3 {
				color: #f00;
			}

		}

		.h_box2 {
			display: block;

			.h_imgList {
				display: flex;
				flex-wrap: wrap;
				margin-top: 22rpx;
			}
		}
	}

	.detail {
		padding: 20rpx 20rpx 160rpx;
		box-sizing: border-box;

		.copy {
			background: var(--theme-color);
			color: #fff;
			font-size: 24rpx;
			display: inline-block;
			padding: 0 10rpx;
			height: 50rpx;
			line-height: 50rpx;
			border-radius: 4rpx;
			margin-left: 20rpx;
		}

		&-title {
			font-size: 30rpx;
			color: #333;
			font-weight: bold;
			height: 90rpx;
			line-height: 90rpx;
			border-bottom: 1rpx solid #e5e5e5;
		}

		/deep/ .nt-card {
			border-radius: 20rpx;
			margin-bottom: 20rpx;

			&-header {
				&__sub {
					margin-left: 20rpx;
					color: #f00;
				}
			}
		}

		&-tip {
			font-size: 30rpx;
			text-align: center;
			line-height: 90rpx;
			color: #666;
		}

		&-footer {
			display: flex;
			align-items: center;
			justify-content: space-between;
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			height: 100rpx;
			padding: 0 20rpx;
			box-sizing: border-box;
			background: #fff;
			box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.2);

			&__btn {
				border-radius: 60rpx;
				border: 1rpx solid var(--theme-color);
				color: var(--theme-color);
				font-size: 24rpx;
				height: 60rpx;
				line-height: 58rpx;
				padding: 0 20rpx;
				min-width: 120rpx;
				text-align: center;
			}
		}
	}

	.card {
		border-radius: 20rpx;
		background: #fff;
		box-sizing: border-box;

		.vertical {
			display: block;
		}

		.end {
			justify-content: flex-end;
		}

		.start {
			justify-content: flex-start;
		}

		.center {
			justify-content: center;
		}

		.space {
			justify-content: space-between;
		}

		.a-end {
			align-items: flex-end;
		}

		.a-start {
			align-items: flex-start;
		}

		.a-center {
			align-items: center;
		}

		.amount {
			font-size: 34rpx;
			font-weight: bold;
			color: #f00
		}

		.subtitle {
			font-size: 28rpx;
			font-weight: bold;
			color: #333;
			height: 80rpx;
			line-height: 80rpx;
			border-bottom: 1rpx solid #e5e5e5;
			width: 100%;
			text-align: left;
			text-align-last: left;
		}

		&.pad {
			padding: 20rpx;
		}

		&-showlog {
			text-align: center;
			margin: 20rpx 0;

			.btn {

				padding: 0 20rpx;
				height: 50rpx;
				line-height: 50rpx;
				color: #fff;
				text-align: center;
				background-color: var(--theme-color);
				display: inline-block
			}
		}

		&-eventlog {
			/deep/ .card-item__label {
				width: auto;
				font-weight: normal;
			}

			.card-item__label {
				width: 260rpx;
			}
		}

		&-item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx 0;
			font-size: 26rpx;

			.red {
				color: #f00
			}

			&__label {
				width: 150rpx;
				color: #666;
				text-align: justify;
				text-align-last: justify;
				margin-right: 50rpx;
				font-weight: bold;
			}

			&__right {
				display: flex;
				align-items: center;
				flex: 1;
				color: #333;
				flex-shrink: 0;

				&.block {
					display: block;
				}

				&.end {
					justify-content: flex-end;
				}
			}

			&__remarks {
				padding: 0 10rpx;
				box-sizing: border-box;
				max-width: 70%
			}

			&__cell {
				flex: 1;
			}
		}
	}

	.progress-container {
		position: fixed;
		top: 0;
		left: 0;
		z-index: 99;
		background: rgba(0, 0, 0, .2);
		width: 750rpx;
		height: 100vh;
		display: flex;
		align-items: center;
		justify-content: center;

		.progress-box {
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 30rpx;

			.text {
				margin-bottom: 20rpx;
			}
		}
	}
	.typetable-footer{
		display:flex;
		align-items: center;
		// flex-wrap: wrap;
		justify-content: space-between;
		padding-top: 20rpx;
		border-top:1rpx solid #f5f5f5;
		margin-top: 10rpx;
		color:#333;
		text{
			color: #666
		}
	}
	.typetable-icon{
		transform: rotate(90deg)
	}
</style>